import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'incomeAnalysisM',
  state: {},
  effects: {
    // 获取收益分解
    *getIncome({ payload, callback }, { call, put }) {
      const res = yield call(api.incomeAnalysis.getIncome, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },
    // 获取超额收益趋势
    *getExcessTrend({ payload, callback }, { call, put }) {
      const res = yield call(api.incomeAnalysis.getExcessTrend, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },
    // 获取因子变革数据
    *factorContributionDetail({ payload, callback }, { call, put }) {
      const res = yield call(api.incomeAnalysis.factorContributionDetail, payload);
      // const res = yield call(api., payload);
      // let res = {
      //   code: 0,
      //   data: {
      //     data1: [
      //       { id: 1, factor: '111', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 2, factor: '222', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 3, factor: '333', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 4, factor: '444', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 5, factor: '555', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 6, factor: '666', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 7, factor: '777', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 8, factor: '888', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 9, factor: '999', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 0, factor: '000', avg_expouse: 1.231, return_contribution: 0.12 },
      //     ],
      //     data2:[
      //       { id: 1, factor: '111', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 2, factor: '222', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 3, factor: '333', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 4, factor: '444', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 5, factor: '555', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 6, factor: '666', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 7, factor: '777', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 8, factor: '888', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 9, factor: '999', avg_expouse: 1.231, return_contribution: 0.12 },
      //       { id: 0, factor: '000', avg_expouse: 1.231, return_contribution: 0.12 },
      //     ]
      //   }
      // }
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },

    // 获取收益分解
    *factorExposure({ payload, callback }, { call, put }) {
      // const res = yield call(api., payload);
      let res = {
        code: 0,
        data: {
          dayIncome: {
            xAxis: ['2021-02-01', '2021-02-02', '2021-02-03'],
            series: [
              {
                name: '超额暴露度（日）',
                data: [0.08, -0.16, 0.22],
              },
              {
                name: '因子收益率（日）',
                data: [-0.16, -0.28, 0.09],
              },
              {
                name: '因子收益贡献（日）',
                data: [0.24, 0.12, 0.13],
              },
            ],
          },
          allIncome: {
            xAxis: ['2021-02-01', '2021-02-02', '2021-02-03'],
            series: [
              {
                name: '超额暴露度（日）',
                data: [0.08, -0.16, 0.22],
              },
              {
                name: '因子收益率（日）',
                data: [-0.16, -0.28, 0.09],
              },
              {
                name: '因子收益贡献（日）',
                data: [0.24, 0.12, 0.13],
              },
            ],
          },
        },
      };
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },

    // 获取股收益贡献
    *stockContribution({ payload, callback }, { call, put }) {
      // const res = yield call(api., payload);
      let res = {
        code: 0,
        data: {
          dataSource: [
            { tradingCode: 1, tradingName: '111', avg_weight: 1.231, bench_weight: 0.12 },
            { tradingCode: 21, tradingName: '111', avg_weight: 1.231, bench_weight: 0.12 },
            { tradingCode: 31, tradingName: '111', avg_weight: 1.231, bench_weight: 0.12 },
            { tradingCode: 41, tradingName: '111', avg_weight: 1.231, bench_weight: 0.12 },
            { tradingCode: 51, tradingName: '111', avg_weight: 1.231, bench_weight: 0.12 },
          ],
        },
      };
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },

    // 因子信息查询
    *stockContributionInfo({ payload, callback }, { call, put }) {
      // const res = yield call(api., payload);
      let res = {
        code: 0,
        data: {
          dataSource: [
            { id: 1, name: '111', contribution: 1.231, bench_weight: 0.12 },
            { id: 21, name: '111', contribution: 1.231, bench_weight: 0.12 },
            { id: 31, name: '111', contribution: 1.231, bench_weight: 0.12 },
            { id: 41, name: '111', contribution: 1.231, bench_weight: 0.12 },
            { id: 51, name: '111', contribution: 1.231, bench_weight: 0.12 },
          ],
        },
      };
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },

    // 资产因子信息折柱图
    *stockContributionData({ payload, callback }, { call, put }) {
      // const res = yield call(api., payload);
      let res = {
        code: 0,
        data: {
          xAxis: ['2021-02-01', '2021-02-02', '2021-02-03'],
          series: [
            {
              name: '资产超额权重（日）',
              data: [0.08, -0.16, 0.22],
            },
            {
              name: '资产累积收益率（日）',
              data: [-0.16, -0.28, 0.09],
            },
            {
              name: '主动收益贡献（日）',
              data: [0.24, 0.12, 0.13],
            },
          ],
        },
      };
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res.msg ? res.msg : '未知错误');
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
